package com.mycomp.cm.controller;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
import com.mycomp.cm.model.User;

@Component
public class LoginValidator implements Validator {

	public boolean supports(Class clazz) {
		return User.class.isAssignableFrom(clazz);
	}

	public void validate(Object obj, Errors errors) {
		
		User user = (User) obj;
		if (user.getUserName() == null || user.getUserName().length() == 0) {
			errors.rejectValue("userName", "error.empty.field", "Default error message");
		}
		if (user.getPassword() == null || user.getPassword().length() == 0) {
		}
		
//		ValidationUtils.rejectIfEmpty(errors, field, errorCode)
		
	}
}
